#include <stdio.h>
#include <stdlib.h>

int Max3 ( int A, int B, int C );

int DivideAndConquer ( int List[], int left, int right );

int main ( int argc, char const *argv[] ) {
    int *arr, *ap, len, i;
    scanf("%d", &len);
    if ( len > 100000 ) return EXIT_FAILURE;
    arr = malloc(sizeof(int)*len);
    for ( i = 0; i < len; i++) {
        ap = arr + i;
        scanf("%d",&ap);
    }
    printf("%d",DivideAndConquer(arr, 0, len-1));
    free(arr);
    return 0;
}

int Max3 ( int A, int B, int C ) {
    return A>B ? A>C ? A : C : B>C ? B : C;
}

int DivideAndConquer ( int List[], int left, int right ) {
    int MaxLeftSum, MaxRightSum;
    int MaxLeftBorderSum, MaxRightBorderSum;

    int LeftBorderSum, RightBorderSum;
    int center, i;

    if ( left == right ) {
            if ( List[left] > 0 ) return List[left];
            else return 0;
        }

    center = ( left + right ) / 2;
    MaxLeftSum = DivideAndConquer(List, left, center);
    MaxRightSum = DivideAndConquer(List, center+1, right);

    MaxLeftBorderSum = 0; LeftBorderSum = 0;
    for ( i = center; i >= left; i-- ) {
        LeftBorderSum+=List[i];
        if ( LeftBorderSum > MaxLeftBorderSum)
            MaxLeftBorderSum = LeftBorderSum;
    }

    MaxRightBorderSum = 0; MaxRightSum = 0;
    for ( i = center; i <= right; i++ ) {
        RightBorderSum+=List[i];
        if ( RightBorderSum > MaxRightBorderSum )
            MaxRightBorderSum = RightBorderSum;
    }

    return Max3(MaxLeftSum, MaxRightSum, MaxLeftBorderSum+MaxRightBorderSum);
}

